
#include "KmyMath.h"

int getHighestBit(s32 n){
	int b = 0;
    while((1<<(b+1))-1<n){
		b+=1;
	}
	return b;
}

int getSmallest2exp(s32 n){
	int b = 0;
	while((1<<b)<n){
		b+=1;
	}
	return b;
}

int power(int a, int b){
	int s = 1;
	while (b>0){
		s = s*a;
		b--;
	}
	return s;
}

int kmy_round(float f){
    return (int)(f+0.5);
}

int kmy_roundup(float f){
    if (f-(int)f>0.00001){
        return (int)f+1;
    }else{
        return (int)f;
    }
}

u16 RGB16(u8 r, u8 g, u8 b){
    return (u16)((b<<10) + (g<<5) + r);
	
}

int* numToFrame(int n, int length){
	n = MAX(0, n);
	int* frame = new int[length];
	int max = power(10, length)-1;
	if (n>max){
		n = max;
	}

	for (int i=length-1; i>=0; i--){
		int m = n;
		n = n/10;
		frame[i] = m-n*10;
	}
	return frame;
}
